#ifndef CELLSTREAMEXPORTVISITOR_H_JM_20121206
#define CELLSTREAMEXPORTVISITOR_H_JM_20121206

// ## jm4bbx
#include "../../common_bbx/tables/BoxDataTable.h"
// ## c++
#include <ostream>

namespace jm4bbx {

	class  CellStreamExportVisitor : public BoxDataTable::CellVisitor {
	public:

		CellStreamExportVisitor(std::ostream* stream) 
			: stream_(stream), firstValue_(true) { }

		virtual void visit(BoxDataTable::ValueCell<int>* v) override {
			dump(v->getValue());
		}


		virtual void visit(BoxDataTable::ValueCell<std::string>* v) override {
			dump(v->getValue());
		}

	protected:

		template<typename T> 
		void dump(T value) {
			if (firstValue_) {
				firstValue_ = false;
				(*stream_) << value;
			}
			else {
				(*stream_) << "," << value;
			}
		}
	private:
		std::ostream* stream_;
		bool firstValue_;
	};

} // namespace jm4bbx


#endif
